package com.example.service.impl;

import cn.hutool.crypto.SecureUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.common.ResultCode;
import com.example.dao.*;
import com.example.entity.Chengji;
import com.example.exception.CustomException;
import com.example.service.ChengjiService;
import com.example.vo.ChengjiVo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;
import java.util.Map;

@Service("chengjiService")
public class ChengjiServiceImpl extends ServiceImpl<ChengjiDao, Chengji> implements ChengjiService {

    @Resource
    private ChengjiDao chengjiDao;

    public Chengji add(Chengji chengji) {
		
	   //youquchong1
        chengji.setAddtime(new Date());
        chengjiDao.insert(chengji);
        return chengji;
    }
	
	@Override    public List<Map<String,Object>> chengji_tj_yuanxi() {    List<Map<String,Object>> returnMap = chengjiDao.chengji_tj_yuanxi();    return returnMap;    }    @Override    public List<Map<String,Object>> chengji_tj_zhuanye() {    List<Map<String,Object>> returnMap = chengjiDao.chengji_tj_zhuanye();    return returnMap;    }    @Override    public List<Map<String,Object>> chengji_tj_xuenian() {    List<Map<String,Object>> returnMap = chengjiDao.chengji_tj_xuenian();    return returnMap;    }    @Override    public List<Map<String,Object>> chengji_tj_jingsaihuojiangrenshu() {    List<Map<String,Object>> returnMap = chengjiDao.chengji_tj_jingsaihuojiangrenshu();    return returnMap;    }    @Override    public List<Map<String,Object>> chengji_tj_shengjihuojiangrenshu() {    List<Map<String,Object>> returnMap = chengjiDao.chengji_tj_shengjihuojiangrenshu();    return returnMap;    }    @Override    public List<Map<String,Object>> chengji_tj_guojiajirenshu() {    List<Map<String,Object>> returnMap = chengjiDao.chengji_tj_guojiajirenshu();    return returnMap;    }    
	
    public void delete(Long id) {
        chengjiDao.deleteById(id);
    }
	

    public void update(Chengji chengji) {
        //youquchong2
        chengjiDao.updateById(chengji);
    }
	
	@Override
    public List<Map<String, Object>> daochuexcel() {
        return chengjiDao.daochuexcel();
    }

    @Override
    public Chengji findById(Integer id) {
        return chengjiDao.selectById(id);
    }

    public ChengjiVo findPage(ChengjiVo chengjiVo) {
        LambdaQueryWrapper<Chengji> wrapper = Wrappers.lambdaQuery();
		wrapper.like(ObjectUtils.isNotEmpty(chengjiVo.getXuehao()), Chengji::getXuehao,chengjiVo.getXuehao());        wrapper.like(ObjectUtils.isNotEmpty(chengjiVo.getXingming()), Chengji::getXingming,chengjiVo.getXingming());        wrapper.like(ObjectUtils.isNotEmpty(chengjiVo.getYuanxi()), Chengji::getYuanxi,chengjiVo.getYuanxi());        wrapper.like(ObjectUtils.isNotEmpty(chengjiVo.getBanji()), Chengji::getBanji,chengjiVo.getBanji());        wrapper.like(ObjectUtils.isNotEmpty(chengjiVo.getZhuanye()), Chengji::getZhuanye,chengjiVo.getZhuanye());        wrapper.like(ObjectUtils.isNotEmpty(chengjiVo.getXuenian()), Chengji::getXuenian,chengjiVo.getXuenian());        wrapper.like(ObjectUtils.isNotEmpty(chengjiVo.getQudechengji()), Chengji::getQudechengji,chengjiVo.getQudechengji());        wrapper.like(ObjectUtils.isNotEmpty(chengjiVo.getJingsaihuojiangrenshu()), Chengji::getJingsaihuojiangrenshu,chengjiVo.getJingsaihuojiangrenshu());        wrapper.like(ObjectUtils.isNotEmpty(chengjiVo.getShengjihuojiangrenshu()), Chengji::getShengjihuojiangrenshu,chengjiVo.getShengjihuojiangrenshu());        wrapper.like(ObjectUtils.isNotEmpty(chengjiVo.getGuojiajirenshu()), Chengji::getGuojiajirenshu,chengjiVo.getGuojiajirenshu());        wrapper.like(ObjectUtils.isNotEmpty(chengjiVo.getBeizhu()), Chengji::getBeizhu,chengjiVo.getBeizhu());        
        Page<Chengji> page = new Page<>(chengjiVo.getCurrent(),chengjiVo.getCurrentNum());
        chengjiDao.selectPage(page,wrapper);
        List<Chengji> chengjis = page.getRecords();
        chengjiVo.setList(chengjis);
        chengjiVo.setPages(page.getPages());
        chengjiVo.setTotal(page.getTotal());
        chengjiVo.setCurrent(page.getCurrent());
        chengjiVo.setCurrentNum(page.getSize());
        return chengjiVo;
    }

    @Override
    public void deleteList(List<Chengji> list) {
        List<Integer> ids =  list.stream().map(Chengji::getId).collect(Collectors.toList());
        chengjiDao.deleteBatchIds(ids);
    }
	
	
	
	
	
	//youxxianxci
}
